Lua/Client/ClientSound/Static Functions/Create
From JC2-MP Documentation
< Lua | Client | ClientSound
Returns | ClientSound |
---|---|
Prototype | ClientSound.Create(AssetLocation, table) |
Description | No description |
Contents
Required values
Type
Name
Notes
Vector3
position
number
bank_id
number
sound_id
Optional values
These values can be found in the sound libraries listed below, under the "Parameters" list for each sound.
Type
Name
Notes
number
variable_id_distance
Tell the game the index of the (distance) parameter.
number
variable_id_focus
Tell the game the index of the focus parameter.
number
variable_id_rain
Tell the game the index of the precipitation parameter.
number
variable_id_time_of_day
Tell the game the index of the timeofday parameter.
number
variable_id_timeline
Tell the game the index of the timeline parameter.
Example
Create the Mile High Club music where you click
sound = nil
Events:Subscribe("MouseDown", function(args)
if args.button ~= 1 then
return
end
Chat:Print("Creating sound", Color.White)
-- If a sound is already playing, remove it. This makes sure only one sound plays at once.
CleanUp()
local result = Physics:Raycast(
Camera:GetPosition(),
Camera:GetAngle() * Vector3.Forward,
0,
100
)
local spawnArgs = {
position = result.position + result.normal * 0.5,
bank_id = 25,
sound_id = 148,
variable_id_focus = 0
}
sound = ClientSound.Create(AssetLocation.Game, spawnArgs)
end)
function CleanUp()
if sound then
sound:Remove()
sound = nil
end
end
-- Make sure to clean up the sound on module unload.
Events:Subscribe("ModuleUnload", CleanUp)